server {
    listen 81;
    server_name www.besteasylearn.com;

    lua_code_cache off;

    #location / {
    #    alias /opt/andrew_git/nginx_test/;
    #    index index.html;
    #}

     #模拟这个是手机站
    location /m {

        if ( $http_user_agent !~* "(MIDP)|(WAP)|(UP.Browser)|(Smartphone)|(Obigo)|(Mobile)|(AU.Browser)|(Android)") {
            rewrite  ^/(.*)$  http://www.besteasylearn.com:81/index.html last;  #此处index就用$uri去掉m/后的变量 
        }

        alias /opt/andrew_git/nginx_test/m/;
        index  index.html;
    }

    location / {
        if ( $http_user_agent ~* "(MIDP)|(WAP)|(UP.Browser)|(Smartphone)|(Obigo)|(Mobile)|(AU.Browser)|(Android)") {
            rewrite  ^/(.*)$  http://www.besteasylearn.com:81//m/$uri last;
        }
        alias /opt/andrew_git/nginx_test/;
        index  index.html;
    }

    #前端按版本号打包后按?v=1.0.0方式访问配置
    location /res {

        if ($request_uri ~* "^/res/(.*)\?v=(.*)$") {
            set $version $2;
            set $beforePath $1;
            rewrite .* /res/$version/$beforePath? redirect; 
        }

        alias  /opt/andrew_git/nginx_test/res/;
        index  index.html;
    }

    #gzip压缩
    location /pic {
        gzip on;
        gzip_min_length 1k;
        gzip_buffers 4 16k;
        #gzip_http_version 1.0;
        gzip_comp_level 4;
        gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/jpg image/gif image/png application/json;
        gzip_vary off;
        gzip_disable "MSIE [1-6]\.";     
        alias  /opt/andrew_git/nginx_test/pic/;
        index  index.html;
    }
    
    
    #gzip压缩关闭
    location /pic2 {
        alias  /opt/andrew_git/nginx_test/pic2/;
        index  index.html;
    }

    location / {
        default_type 'text/plain';
        content_by_lua_block {
           ngx.say('hello openresty-lua');
        }
    }

    

}
